#define  _CRT_SECURE_NO_WARNINGS
/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/

class Solution {
public:
    vector<vector<int>> levelOrder(Node* root) {
        vector<vector<int>> ret;
        if (root == nullptr)return ret;
        queue<Node*> q;
        q.push(root);
        while (q.size())
        {
            int num = q.size();
            ret.push_back(vector<int>());
            while (num--)
            {
                Node* tmp = q.front();
                q.pop();
                if (tmp)
                {
                    ret.back().push_back(tmp->val);
                    for (auto e : tmp->children) q.push(e);
                }
            }
        }
        return ret;
    }
};